home *** CD-ROM | disk | FTP | other *** search
- {**************************************************************************************
- * *
- * Module Name : BITVIEW.PAS *
- * Type : PROGRAM *
- * *
- **************************************************************************************}
-
- program Bitview;
-
-
- {$R BITVIEW.RES}
-
-
- uses
- WObjects, WinTypes, WinProcs, WinDos, Strings, StdDlgs, Files;
-
-
- type
- MDIBitmapApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
-
- PMDIParentWindow = ^TMDIParentWindow;
- TMDIParentWindow = object(TMDIWindow)
- constructor Init(ATitle : PChar; AMenu : HMenu);
-
- procedure MDIFileOpen(var Msg : TMessage);
- virtual cm_First + cm_MDIFileOpen;
-
- procedure WMQueryNewPalette(var Msg : TMessage);
- virtual wm_First + wm_QueryNewPalette;
- procedure WMPaletteChanged(var Msg : TMessage);
- virtual wm_First + wm_PaletteChanged;
- end;
-
-
- PMDIChildWindow = ^TMDIChildWindow;
- TMDIChildWindow = object(TWindow)
- ChildBitmap : HBitmap;
- ChildPalette : hPalette;
- BitmapWidth,
- BitmapHeight : LongInt;
-
- constructor Init(AParent : PWindowsObject; ATitle : PChar; BHandle : HBitmap;
- W, H : LongInt; MyPal : HPalette);
- destructor Done; virtual;
-
- function GetClassName : Pchar ; virtual;
- procedure AdjustScroller;
- procedure GetWindowClass(var AWndClass : TWndClass);
- virtual;
- procedure Paint(PaintDC : HDC; var PaintInfo : TPaintStruct);
- virtual;
-
- procedure WMSize(var Msg : TMessage);
- virtual wm_First + wm_Size;
- procedure WMQueryNewPalette(var Msg : TMessage);
- virtual wm_First + wm_QueryNewPalette;
- procedure WMPaletteChanged(var Msg : TMessage);
- virtual wm_First + wm_PaletteChanged;
- procedure WMMDIActivate(var Msg : TMessage);
- virtual wm_First + wm_MDIActivate;
- end;
-
-
-
-
- { This constructor centers the program within the current workspace }
-
- constructor TMDIParentWindow.Init(ATitle : PChar; AMenu : HMenu);
- begin
- TMDIWindow.Init(ATitle, AMenu);
- with Attr do
- begin
- X := GetSystemMetrics(sm_CXScreen) div 8;
- Y := GetSystemMetrics(sm_CYScreen) div 8;
- W := X * 6;
- H := Y * 6;
- end;
- end;
-
-
-
-
- { This procedure opens up a BITMAP file. Currently works with compressed and compressed
- files. There is no logic to contend with corrupted files, though. }
-
- procedure TMDIParentWindow.MDIFileOpen(var Msg : TMessage);
- var
- FileName : TFilename;
- Bitmap : HBitmap;
- Palette : hPalette;
- Width,
- Height : LongInt;
- hPal : hPalette;
-
- begin
- if CanClose then
- begin
- FileName[0] := #0;
- Bitmap := 0;
- Palette := 0;
- if FileDialog(HWindow, FileName, False) then
- begin
- SetCursor(LoadCursor(0, idc_Wait));
- Bitmap := LoadBitmap(FileName, HWindow, Width, Height, Palette);
- SetCursor(LoadCursor(0, idc_Arrow));
- if (Bitmap = 0) then
- MessageBox(HWindow, 'File is not a BITMAP', 'Error',
- mb_IconExclamation or mb_ok)
- else
- begin
- Application^.MakeWindow(New(PMDIChildWindow,
- Init(@Self, FileName, Bitmap, Width, Height, Palette)));
- end;
- end;
- end;
- end;
-
-
-
-
- { This procedure is here because Windows only sends QUERYNEWPALETTE messages to the Appli-
- cations in use, NOT their MDI windows. }
-
- procedure TMDIParentWindow.WMQueryNewPalette(var Msg : TMessage);
- var
- CurrentMDIActiveChild : hWnd;
- MDIClientWindow : hWnd;
-
- begin
- MDIClientWindow := ClientWnd^.hWindow;
-
- CurrentMDIActiveChild := SendMessage (MDIClientWindow, WM_MDIGETACTIVE, 0, 0);
- if (CurrentMDIActiveChild <> 0) then
- SendMessage(CurrentMDIActiveChild, WM_QUERYNEWPALETTE, MDIClientWindow, 0);
- end;
-
-
-
-
- { This procedure is here because Windows only sends PALETTECHANGED messages to the Appli-
- cations in use, NOT their MDI windows. }
-
- procedure TMDIParentWindow.WMPaletteChanged(var Msg : TMessage);
- var
- MDIClientWindow : hWnd;
- MDIChildWindow : hWnd;
- CurrentMDIActiveChildWindow : hWnd;
-
- begin
- MDIClientWindow := GetWindow(hWindow, GW_CHILD);
- MDIChildWindow := GetWindow(MDIClientWindow, GW_CHILD);
-
- if (MDIChildWindow <> 0) then
- begin
- CurrentMDIActiveChildWindow := SendMessage (MDIClientWindow, WM_MDIGETACTIVE, 0, 0);
- repeat
- if not (MDIChildWindow = CurrentMDIActiveChildWindow) then
- SendMessage(MDIChildWindow, WM_PALETTECHANGED, Msg.wParam, Msg.lParam);
- MDIChildWindow := GetNextWindow(MDIChildWindow, GW_HWNDNEXT);
- until (MDIChildWindow = 0);
- end;
- end;
-
-
-
-
- { ***************** End App Window Methods, now Child methods ***************************** }
-
-
-
-
- constructor TMDIChildWindow.Init(AParent : PWindowsObject; ATitle : PChar; BHandle : HBitmap;
- W, H : LongInt; MyPal : HPalette);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Style := Attr.Style or ws_VScroll or ws_HScroll;
- ChildBitmap := BHandle;
- ChildPalette := MyPal;
- BitmapWidth := W;
- bitmapHeight := H;
- Scroller := New(PScroller, Init(@Self, 1, 1, 200, 200));
- Scroller^.TrackMode := False;
- Scroller^.AutoMode := False;
- end;
-
-
-
-
- destructor TMDIChildWindow.Done;
- begin
- if (ChildBitmap <> 0) then
- DeleteObject(ChildBitmap);
- if (ChildPalette <> 0) then
- DeleteObject(ChildPalette);
- TWindow.Done;
- end;
-
-
-
-
- { This procedure picks out an ICON to use when minimized }
-
- procedure TMDIChildWindow.GetWindowClass(var AWndClass : TWndClass);
- begin
- TWindow.GetWindowClass(AWndClass);
- AWndClass.HIcon := LoadIcon(HInstance, 'ICON_1');
- end;
-
-
-
-
- function TMDIChildWindow.GetClassName : PChar;
- begin
- GetClassName := 'MDIChild';
- end;
-
-
-
-
- { This procedure is called only from the APP, not Windows. }
-
- procedure TMDIChildWindow.WMQueryNewPalette(var Msg : TMessage);
- var
- PalDC : HDC;
- NumberOfChangedColors : Word;
- MDIClientWindow : hWnd;
- hOldPal : hPalette;
-
- begin
- MDIClientWindow := GetParent(hWindow);
- PalDC := GetDC(MDIClientWindow);
- hOldPal := SelectPalette(PalDC, ChildPalette, False);
- NumberOfChangedColors := RealizePalette(PalDC);
- if (NumberOfChangedColors > 0) then
- InvalidateRect(hWindow, nil, False);
- if (hOldPal <> 0) then
- SelectPalette(PalDC, hOldPal, False);
- ReleaseDC(MDIClientWindow,PalDC);
- end;
-
-
-
-
- { This procedure is called only from the APP, not Windows. }
-
- procedure TMDIChildWindow.WMPaletteChanged(var Msg : TMessage);
- var
- PalDC : HDC;
- MDIPalette : hPalette;
- hOldPal : hPalette;
-
- begin
- if ((ChildPalette <> 0) and (ChildBitmap <> 0)) then
- begin
- PalDC := GetDC(hWindow);
- hOldPal := SelectPalette(PalDC, ChildPalette, True);
- RealizePalette(PalDC);
- UpdateColors(PalDC);
- if (hOldPal > 0) then
- SelectPalette(PalDC, hOldPal, False);
- ReleaseDC(hWindow,PalDC);
- end
- end;
-
-
-
-
- { This procedure is needed to tell all other Child windows that this window is taking the
- palette }
-
- procedure TMDIChildWindow.WMMDIActivate(var Msg : TMessage);
- var
- MDIClientWindow : hWnd;
- MDIParentWindow : hWnd;
-
- begin
- if (Msg.wParam = 1) then
- begin
- MDIClientWindow := GetParent(hWindow);
- MDIParentWindow := GetParent(MDIClientWindow);
- SendMessage (MDIParentWindow, WM_QUERYNEWPALETTE, MDIClientWindow, 0);
- end;
- end;
-
-
-
-
- procedure TMDIChildWindow.Adjustscroller;
- var
- ClientRect : TRect;
-
- begin
- GetClientRect(hWindow, ClientRect);
- with ClientRect do
- Scroller^.SetRange((BitmapWidth - (Right - Left)), (BitmapHeight - (Bottom - Top)));
- InvalidateRect(hWindow, nil, False);
- end;
-
-
-
-
- procedure TMDIChildWindow.WMSize(var Msg : TMessage);
- begin
- TWindow.WMSize(Msg);
- if not (Msg.WParam = sizeIconic) then
- AdjustScroller;
- end;
-
-
-
-
- procedure TMDIChildWindow.Paint(PaintDC : HDC; var PaintInfo : TPaintStruct);
- var
- MemDC : HDC;
- Image, OldBitmap : HBitmap;
- W, H : LongInt;
-
- begin
- Image := ChildBitmap;
- W := BitmapWidth;
- H := BitmapHeight;
- if (Image <> 0) then
- begin
- MemDC := CreateCompatibleDC(PaintDC);
- OldBitmap := SelectObject(MemDC, Image);
- SelectPalette(PaintDC, ChildPalette, True);
- SelectPalette(MemDC, ChildPalette, True);
- BitBlt(PaintDC, 0, 0, W, H, MemDC, 0, 0, SRCCopy);
- SelectObject(MemDC, OldBitmap);
- DeleteDC(MemDC);
- end;
- end;
-
-
-
-
- procedure MDIBitmapApplication.InitMainWindow;
- begin
- MainWindow := New(PMDIParentWindow, Init('MDI Bitmap Viewer 1.00',
- LoadMenu(HInstance, 'MDIMenu')));
- end;
-
-
-
-
- var
- MDIBitmapApp: MDIBitmapApplication;
-
- begin
- MDIBitmapApp.Init('MDI Bitmap Viewer 1.00');
- MDIBitmapApp.Run;
- MDIBitmapApp.Done;
- end.
-